package com.example.exam.securityConfig.handler;


import com.example.exam.util.JSON;
import com.example.exam.util.RespBean;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Component
public class MyLogoutSuccessHandler implements LogoutSuccessHandler {



    @Override
    public void onLogoutSuccess(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Authentication authentication) throws IOException, ServletException {
        //没有logout不走这里、若使用security的formLogin则自己添加业务实现（移除token等等）
        //如果是使用SESSION机制,则需要销毁机制和相应的cookie中的SESSIONID
        //如果是使用TOKEN机制,则需要在Redis中销毁相应的TOKEN,以及在header中销毁

        httpServletResponse.setCharacterEncoding("utf-8");
        httpServletResponse.getWriter().write(JSON.writeToString(RespBean.ok("退出成功")));
    }
}
